﻿using remove_file.Utils;
using System;
using System.Windows.Forms;

namespace remove_file
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void SelectDirButton_Click(object sender, EventArgs e)
        {
            var resutlt = this.removeDirBrowserDialog.ShowDialog();
            if (resutlt == DialogResult.OK)
            {
                this.removeDirInput.Text = this.removeDirBrowserDialog.SelectedPath;
            }
        }

        private void RemoveDirButton_Click(object sender, EventArgs e)
        {
            this.logTextBox.Text = "";
            var removeDirPath = this.removeDirInput.Text;
            FileUtils.RemoveFileErrorList errorList = new FileUtils.RemoveFileErrorList();
            bool result = FileUtils.RemoveDirectory(removeDirPath, errorList);
            if (!result)
            {
                this.logTextBox.Text = errorList.ToString();
            }
        }

        private void Form1_DragEnter(object sender, DragEventArgs e)
        {
            e.Effect = e.Data.GetDataPresent(DataFormats.FileDrop)? DragDropEffects.All : DragDropEffects.None;
        }

        private void Form1_DragDrop(object sender, DragEventArgs e)
        {
            string path = ((Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
            this.removeDirInput.Text = path;
        }
    }
}
